﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using System.IO;
public partial class Rechristen : System.Web.UI.Page
{
    string name;
  
    int fileid;
    int dirid;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            name = Session["admin"].ToString();
            if (Convert.ToInt32(Request.QueryString["fileid"].ToString())!=0)
            {
                 
                 Labdirorfile.Text = "请输入新的文件名";
            }
            else
            {
               
                Labdirorfile.Text = "请输入新的文件夹名";
                
            }
        }
    }
    protected void Butture_Click(object sender, EventArgs e)
    {
        
      
        string q = Request.QueryString["q"].ToString();
        string p = Request.QueryString["p"].ToString();
        string dd = Request.QueryString["dd"].ToString();

        name = Session["admin"].ToString();
        fileid = Convert.ToInt32(Request.QueryString["fileid"].ToString());
        dirid = Convert.ToInt32(Request.QueryString["dirid"].ToString());
        if (Txtnewname.Text  != string.Empty)
        {

            if (Convert.ToInt32(Request.QueryString["dirid"].ToString()) != 0)
            {
                string labpath = Server.UrlDecode(Request.QueryString["labpath"].ToString());
                string dirname = Server.UrlDecode(Request.QueryString["dirname"].ToString());
                string path = Server.MapPath("Upfile" + "\\" + labpath + "\\" + dirname );
                string newpath = Server.MapPath("Upfile" + "\\" + labpath + "\\" + Txtnewname.Text.ToString() );
                DirectoryInfo di = new DirectoryInfo(path);
                di.MoveTo(newpath);
                bool b=new DirInfoManager ().Updatebyid (name,dirid ,Txtnewname.Text.ToString());
                
                if (b) { Response.Redirect("../Web/Manager.aspx?q=" + q + "&p=" + p + "&dd=" + dd); }
                

            }
            else
            {
                string fileext = Request.QueryString["fileext"].ToString();
                string labpath = Server.UrlDecode(Request.QueryString["labpath"].ToString());
                string filename = Server.UrlDecode(Request.QueryString["filename"].ToString());
                string path = Server.MapPath("Upfile" + "\\" + labpath + "\\" + filename + fileext);
                string newpath = Server.MapPath("Upfile" + "\\" + labpath + "\\" + Txtnewname.Text.ToString() + fileext);
                FileInfo fi = new FileInfo(path);
                fi.MoveTo(newpath);
                bool b=new FileInfoManager ().Updatebyid (name,fileid , Txtnewname.Text.ToString());
  
                if (b) { Response.Redirect("../Web/Manager.aspx?q=" + q + "&p=" + p + "&dd=" + dd); }
            
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script  defer>alert('新的名字不能为空！');</script>");
        }
    }
}
